package com.test.listeners;

import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import org.apache.struts.action.ActionForm;

public class AttributeListener implements ServletRequestAttributeListener,
		HttpSessionAttributeListener {

	public void attributeAdded(ServletRequestAttributeEvent event) {
		String attributeName=event.getName();
		if(event.getValue() instanceof ActionForm){//判断event.getValue()的值是否是ActionForm类型
			System.out.println("----增加了一个request属性----");
			System.out.println("name="+attributeName+"\tvalue="+event.getValue());
		}

	}

	public void attributeRemoved(ServletRequestAttributeEvent event) {
		System.out.println("----删除了一个request属性----");

	}

	public void attributeReplaced(ServletRequestAttributeEvent event) {
		System.out.println("----覆盖了 一个request属性----");

	}

	public void attributeAdded(HttpSessionBindingEvent event) {
		String attributeName=event.getName();
		if(event.getValue() instanceof ActionForm){//判断event.getValue()的值是否是ActionForm类型
			System.out.println("----增加了一个sessiont属性----");
			System.out.println("name="+attributeName+"\tvalue="+event.getValue());
		}

	}

	public void attributeRemoved(HttpSessionBindingEvent event) {
		System.out.println("----覆盖了 一个Session属性----");

	}

	public void attributeReplaced(HttpSessionBindingEvent event) {
		System.out.println("----覆盖了 一个Session属性----");

	}

}
